import com.javasm.dao.RoomDao;
import com.javasm.entity.Room;
import com.javasm.utils.MybatisHealper;
import org.apache.ibatis.session.SqlSession;
import org.junit.jupiter.api.Test;

import java.util.List;

public class roomtest {


    //查
    @Test
    public void roomtest(){
        SqlSession getsqlsession = MybatisHealper.getsqlsession();
        RoomDao mapper = getsqlsession.getMapper(RoomDao.class);
        List<Room> rooms = mapper.listRoom();
        System.out.println(rooms);
        MybatisHealper.backAndSaveSqlSession(getsqlsession);

    }
    //查
    @Test
    public void listbyCustonerandPushtest(){
        SqlSession getsqlsession = MybatisHealper.getsqlsession();
        RoomDao mapper = getsqlsession.getMapper(RoomDao.class);
        Room room = new Room(3001,2);
        List<Room> rooms = mapper.listbyCustonerandPush(room);
        System.out.println(rooms);
        MybatisHealper.backAndSaveSqlSession(getsqlsession);

    }
    //查两个参数，不用对象传值,用不同的字段的不同的数据，传值，可以自定义用@param来切换新的数据
@Test
    public void listbynameandcategory(){
        SqlSession session  = MybatisHealper.getsqlsession();
    RoomDao mapper = session.getMapper(RoomDao.class);
    List<Room> listbynameandcategory = mapper.listbynameandcategory("小姐姐大11",7);
    System.out.println(listbynameandcategory);
    MybatisHealper.backAndSaveSqlSession(session);

}
        //查新的单个的数据，一般用get开头，返回值是int
    @Test
    public void getroombyid(){
        SqlSession session  = MybatisHealper.getsqlsession();
        RoomDao mapper = session.getMapper(RoomDao.class);
        Room roombyid = mapper.getRoombyid(5);
        System.out.println(roombyid);
        MybatisHealper.backAndSaveSqlSession(session);

    }
    @Test
    public void InsertRoomby3(){
        SqlSession session  = MybatisHealper.getsqlsession();
        RoomDao mapper = session.getMapper(RoomDao.class);

        Room room = new Room(1,0000,666666);
        int room1 = mapper.InsertRoom(room);
        System.out.println(room1);
        MybatisHealper.backAndSaveSqlSession(session);

    }

    @Test
    public void updateRoomby4(){
        SqlSession session  = MybatisHealper.getsqlsession();
        RoomDao mapper = session.getMapper(RoomDao.class);

        Room room = new Room(10006,"1515",1515);
        int room1 = mapper.updateByRoomId(room);
        System.out.println(room1);
        MybatisHealper.backAndSaveSqlSession(session);

    }
    @Test
    public void updateRoomby5(){
        SqlSession session  = MybatisHealper.getsqlsession();
        RoomDao mapper = session.getMapper(RoomDao.class);
        Room room = new Room(12);
        int i = mapper.deleteByRoomId(room);
        System.out.println(i);

//        Room room = new Room(10006,"1515",1515);
//        int room1 = mapper.updateByRoomId(room);

        MybatisHealper.backAndSaveSqlSession(session);

    }


}
